package com.dzt.androidframework.express;

import android.content.Context;
import android.widget.CompoundButton;

import com.dzt.androidframework.R;
import com.dzt.androidframework.eventbus.EventBusUtil;
import com.dzt.androidframework.express.javabean.OrderAllEvent;
import com.dzt.androidframework.express.javabean.OrderInfoLitePal;
import com.dzt.androidframework.express.javabean.OrderState;
import com.dzt.androidframework.recycler.OrderSlideViewHolder;
import com.dzt.androidframework.recycler.SlideRecyclerAdapter;
import com.dzt.androidframework.utils.JLogKit;

import java.util.List;

/**
 * Created by M02323 on 2017/9/19.
 */

public class OrderAdapter extends SlideRecyclerAdapter<OrderInfoLitePal> {

	private int type;
	private boolean isEditing = false;

	public OrderAdapter(Context context, List<OrderInfoLitePal> datas, int layoutId, int type) {
		super(context, datas, layoutId);
		this.type = type;
	}

	@Override
	public void convert(OrderSlideViewHolder holder, OrderInfoLitePal data, final int position) {
		holder.bind();
		holder.setText(R.id.tv_order_signed_com, data.getCom());
		holder.setText(R.id.tv_order_signed_num, data.getNu());
		holder.setText(R.id.tv_order_signed_state, OrderState.caseState(data.getState()));
		holder.setText(R.id.tv_order_signed_time, data.getTime());
		holder.setChecked(R.id.cb_order_signed, data.isSelect());
		if (type == OrderState.TYPE_ALL) {
			if (!data.getState().equals("3")) {
				holder.setTextColor(R.id.tv_order_signed_state, context.getResources().getColor(R.color.red));
			} else {
				holder.setTextColor(R.id.tv_order_signed_state, context.getResources().getColor(R.color.black));
			}
		}
		holder.setOnCheckedChangeListener(R.id.cb_order_signed, new CompoundButton.OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
				// To:FragmentOrder_All 改变list的isselect字段
				EventBusUtil.postSync(new OrderAllEvent(position, b, this));
				JLogKit.getInstance().e("setOnCheckedChangeListener pos = " + position);
			}
		});
	}

	public void slideOpen() {
		slideHelper.slideOpen();
		isEditing = true;
	}

	public void slideClose() {
		slideHelper.slideClose();
		isEditing = false;
	}

	public boolean isEditing() {
		return isEditing;
	}
}
